package cn.jsu.oj.judgment.thread;

import cn.jsu.oj.judgment.net.netHandler.JudgeWriteClientHandler;
import cn.jsu.oj.judgment.pojo.JudgeResult;
import lombok.extern.slf4j.Slf4j;

import static cn.jsu.oj.judgment.config.DataStructureConfig.judgeResultQueue;

/**
 * 轮询判题结果 队列，并发给结果写回队列
 */
@Slf4j
public class SendResultThread implements Runnable{

    @Override
    public void run() {
       while (true) {
           try {
               JudgeResult judgeResult = judgeResultQueue.take();
               log.info("序列号 {} 判题结果已发送" , judgeResult.getSerialNumber());
               //发送判题结果写回包
               JudgeWriteClientHandler.channel.writeAndFlush(judgeResult.serialize());
           } catch (Exception e) {
              log.error(e.getLocalizedMessage(),e);
           }
       }
    }
}
